package com.usian.wemedia.controller.v1;

import com.usian.apis.wemedia.WmMaterialControllerApi;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 图片上传
     * @param file  MultipartFile  请求类型： post
     * @param state
     * @return
     */
    @PostMapping("/upload/{state}")
    @Override
    public ResponseResult uploadPicture(@RequestPart("file") MultipartFile file, @PathVariable("state") Integer state) {
        return wmMaterialService.uploadPicture(file,state);
    }

    /**
     * 分页
     * @param dto 封装dto 传递对象
     * @return
     */
    @PostMapping("/list")
    @Override
    public PageResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findPage(dto);
    }

    /**
     * 删除图片
     * @param id
     * @return
     */
    @DeleteMapping("/delById/{id}")
    @Override
    public ResponseResult delById(@PathVariable("id") Integer id) {
        return wmMaterialService.delPicture(id);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @PutMapping("/cancel_collect/{id}")
    @Override
    public ResponseResult cancleCollectionMaterial(@PathVariable("id")  Integer id) {
        return wmMaterialService.updateStatus(id,(short)0);
    }

    /**
     * 收藏图片
     * @param id
     * @return
     */
    @PutMapping("/collect/{id}")
    @Override
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id,(short)1);
    }


}
